//
//  PayManager.h
//  LingVR
//
//  Created by MinLison on 16/7/4.
//  Copyright © 2016年 LingVR. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <StoreKit/StoreKit.h>
#import "NYPurchaseUIManager.h"
NS_ASSUME_NONNULL_BEGIN

FOUNDATION_EXTERN NSString *PayCancelResult;

typedef NS_ENUM(NSInteger, PayType)
{
        PayTypeNone     = -1, // 空值
        PayTypeAlipay   = 1, // 支付宝
        PayTypeWx       = 2, // 微信
        PayTypeApplePay = 3, // ApplePay
        PayTypeiTunes   = 4, // 内购
};
/**
 *  错误码
 */
typedef NS_ENUM(NSInteger, PayiTunesErrorCode) {
        /**
         *  未知错误
         */
        PayiTunesErrorCodeUnknown = SKErrorUnknown,
        /**
         *  服务器不允许当前访问可用
         */
        PayiTunesErrorCodeClientInvalid = SKErrorClientInvalid,
        /**
         *  取消购买
         */
        PayiTunesErrorCodePaymentCancelled = SKErrorPaymentCancelled,
        /**
         *  内购物品ID不正确,没有该商品
         */
        PayiTunesErrorCodePaymentInvalid = SKErrorPaymentInvalid,
        /**
         *  设备不支持内购
         */
        PayiTunesErrorCodePaymentNotAllowed = SKErrorPaymentNotAllowed,
        /**
         *  产品在iTunes未生效
         */
        PayiTunesErrorCodeStoreProductNotAvailable = SKErrorStoreProductNotAvailable,
        /**
         *  用户未授权
         */
        PayiTunesErrorCodeCloudServicePermissionDenied = SKErrorCloudServicePermissionDenied,
        /**
         *  网络错误(iTunes 服务器错误)
         */
        PayiTunesErrorCodeCloudServiceNetworkConnectionFailed = SKErrorCloudServiceNetworkConnectionFailed,
        /**
         *  自己服务器网络错误
         */
        PayiTunesErrorCodeSelfServiceNetworkFailed,
        /**
         *  没有登录
         */
        PayiTunesErrorCodeNotLogin,
        /**
         *  正在恢复上次购买
         */
        PayiTunesErrorCodeRestore,
        /**
         *  商品信息错误
         */
        PayiTunesErrorCodePaymentError,
        /**
         *  本地票据信息为空
         */
        PayiTunesErrorCodeLocalRecepitNULL,
};

typedef void (^VerifyReceiptCompletion)(NSError * _Nullable error);
typedef void(^PayItunesCompletion)(NSArray *_Nullable content, NSError * _Nullable error, _Nullable VerifyReceiptCompletion completion);

@interface PayManager : NSObject
/**
 *  单例
 *
 *  @return self
 */
+ (instancetype)manager;
/**
 *  当前支付 charge
 */
@property (copy, nonatomic, readonly) NSString *currentCharge;

// 在AppDelegate中实现
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(nullable NSDictionary *)launchOptions;

/**
 *  内购
 *
 *  @param goodid     内购物品id
 *  @param completion 完成回调
 */
- (void)payItunes:(NSString *)goodid completion:(PayItunesCompletion)completion;

/**
 恢复内购项目

 @param goodid 内购产品 id
 @param completion  完成回调
 */
- (void)restore:(NSString *)goodid  completion:(PayItunesCompletion)completion;

/**
 是否已经购买过非续期订阅类型物品

 @param goodid 产品 id
 @param completion  完成回调
 */
- (BOOL)isBuy:(NSString *)goodid;


- (void)cancelCurrentBuy;

@end
NS_ASSUME_NONNULL_END
